package com.css.gdzj.gdzjbxgd.modules.reportinfo.controller;

import com.alibaba.fastjson.JSONObject;
import com.css.gdzj.gdzjbxgd.modules.reportinfo.service.HonestGiftChildService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;

/**
 * @author z
 * @date 2020-12-11
 */
@Slf4j
@RestController
@RequestMapping("/honestGiftChilds")
public class HonestGiftChildController {
    @Autowired
    private HonestGiftChildService honestGiftChildService;
    /*@GetMapping("/queryHonestGiftChilds")
    public RestResponse queryHonestGiftChilds(HttpServletRequest request, HonestGiftChildQueryParams queryParams) {
        RestResponse response = null;
        try{
            int curPage = Integer.valueOf(request.getParameter(PlatformPageUtils.CUR_PAGE));
            int pageSize = Integer.valueOf(request.getParameter(PlatformPageUtils.PAGE_SIZE));
            JSONObject jsonObject = honestGiftChildService.queryHonestGiftChilds(queryParams,curPage,pageSize);
            response = RestResponse.succeed(jsonObject);
        }catch (Exception e){
            String errorMessage = "查询失败!";
            log.error(errorMessage,e);
            response = RestResponse.fail(errorMessage);
        }
        return response;
    }

    @GetMapping("{id}")
    public RestResponse getHonestGiftChild(@PathVariable String id) {
        RestResponse response = null;
        try{
            HonestGiftChildEntity honestGiftChild = honestGiftChildService.getHonestGiftChild(id);
            response = RestResponse.succeed(honestGiftChild);
        }catch (Exception e){
            String errorMessage = "获取失败!";
            log.error(errorMessage,e);
            response = RestResponse.fail(errorMessage);
        }
        return response;
    }
    @PostMapping
    public RestResponse saveHonestGiftChild(@RequestBody HonestGiftChildEntity honestGiftChild) {
        RestResponse response = null;
        JSONObject json = new JSONObject();
        try{
            honestGiftChildService.saveHonestGiftChild(honestGiftChild);
            json.put("message", "新增成功!");
            response = RestResponse.succeed(json);
        }catch (Exception e){
            String errorMessage = "新增失败!";
            log.error(errorMessage,e);
            response = RestResponse.fail(errorMessage);
        }
        return response;

    }
    @PutMapping
    public RestResponse updateHonestGiftChild(@RequestBody HonestGiftChildEntity honestGiftChild)  {
        RestResponse response = null;
        JSONObject json = new JSONObject();
        try{
            honestGiftChildService.updateHonestGiftChild(honestGiftChild);
            json.put("message", "修改成功!");
            response = RestResponse.succeed(json);
        }catch (Exception e){
            String errorMessage = "修改失败!";
            log.error(errorMessage,e);
            response = RestResponse.fail(errorMessage);
        }
        return response;
    }
    @DeleteMapping
    public RestResponse deleteHonestGiftChilds(@RequestParam List<String> ids) {
        RestResponse response = null;
        JSONObject json = new JSONObject();
        try{
            honestGiftChildService.deleteHonestGiftChilds(ids);
            json.put("message", "删除成功!");
            response = RestResponse.succeed(json);
        }catch (Exception e){
            String errorMessage = "删除失败!";
            log.error(errorMessage,e);
            response = RestResponse.fail(errorMessage);
        }
        return response;
    }



    @GetMapping("/exportExcel")
    public RestResponse exportFile(HonestGiftChildQueryParams queryParams, HttpServletResponse response){
    RestResponse restResponse = null;
    JSONObject jsonObject = new JSONObject();
    try {
    honestGiftChildService.exportExcel(queryParams,response);
    jsonObject.put("message","导出成功");
    }catch (Exception e){
    String errorMsg = "导出失败";
    log.error("导出失败!",e);
    restResponse = RestResponse.fail(errorMsg);

    }
    return restResponse;
    }

    @GetMapping("/deptTemplate")
    public RestResponse downloadTemplate(){
    RestResponse restResponse = null;
    JSONObject jsonObject = new JSONObject();
    try{
    String fileName = "HonestGiftChild.xlsx";
    platformDownloadUtils.download("filestemplate",fileName);
    jsonObject.put("message","模板下载成功");
    }catch (Exception e){
    log.error("下载失败");
    String message = "下载失败";
    restResponse = RestResponse.fail(message);

    }
    return restResponse;
    }

    @PostMapping("/uploadFile")
    public RestResponse uploadFile(MultipartFile file, HttpServletResponse response){
    RestResponse restResponse = null;
    try{
    String returnMsg =  honestGiftChildService.uploadFile(file,response);
    restResponse = RestResponse.succeed(returnMsg);
    }catch (Exception e){
    String errorMessage = "导入失败!";
    log.error(errorMessage,e);
    restResponse = RestResponse.fail(errorMessage);

    }
    return  restResponse;
    }*/
}